<template>
  <div class="dialog">
    <div class="dialog-con express-container">
      <P><i class="el-icon-set-up" style="color: #4ae2ef;"></i>发货详情</P>
      <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
        <el-form-item label="快递方式">
          <el-select v-model="expressMods.expressType" placeholder="请选择" disabled size="medium" clearable >
            <el-option
              v-for="item in expressMethod"
              :key="item.value"
              :label="item.label"
              :value="item.value + ''">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="快递单号" prop="expressCode">
          <el-input v-model="ruleForm.expressCode"></el-input>
        </el-form-item>
        <el-form-item label="快递费用" prop="extraExpenses">
            <el-input v-model="ruleForm.expressCharges"></el-input>
        </el-form-item>
        <el-form-item label="其他费用" prop="otherCharges">
          <el-input v-model="ruleForm.otherCharges"></el-input>
        </el-form-item>
        <el-form-item  style="margin-top:30px;">
          <el-button type="primary" @click="submitForm('ruleForm')" size="medium">提交</el-button>
          <el-button @click="cancel" size="medium">取消</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>
<script>
  import SplitVertical from "components/common/SplitVertical"
  import {localStorage} from 'js/localStorage'
  export default {
    components: {
      SplitVertical
    },
    inject:['reload'],
    data() {
      return {
        userId:'',
        expressMethod:[{
          value:'X',
          label:"无"
        },{
          value:"A",
          label:"邮政快递"
        },{
          value:'B',
          label:"顺丰快递"
        },{
          value:'C',
          label:'百世快递'
        },{
          value:"D",
          value:"货拉拉"
        }],
        ruleForm: {
          expressCharges: '',
          otherCharges:'',
          expressCode:'',
        },
        rules: {
          expressCharges: [
            { required: true, message: '请输入', trigger: 'change' },
          ],
          otherCharges: [
            { required: true, message: '请输入', trigger: 'change' }
          ],
          expressCode: [
            { required: true, message: '请输入', trigger: 'change' }
          ],
        }
      }
    },
    props:{
      expressMods:{
        type:Object,
        default:{}
      }
    },
    created(){
     this.userId= localStorage.get("userID")
    },
    methods: {
      submitForm(ruleForm) {
        this.$refs[ruleForm].validate((valid) => {
          if (valid) {
            this.submitDelivery()
          } else {
            return false;
          }
        });
      },
      submitDelivery(){
        let param=this.ruleForm
        param['userId']=this.userId
        param['orderId']=this.expressMods.id
        let success=data=>{
          if(data.code=="OK"){
            this.$message.success(data.msg)
            this.$emit("close")
            this.reload()
          }else{
            this.$message.error(data.msg)
          }
        }
        this.api.internalOrderDeliver(param,success)
      },

      cancel() {
        this.$emit("close")
      },
    }
  }
</script>

<style lang="scss" scoped>
  .express-container {
    width: 400px;
    height: 350px;
    p{
      margin: 10px;
    }
    .el-input {
      width: 80%;
    }
    .el-select{
      width: 80%;
    }
  }
</style>
